<template>
  <div class="login-panel">
    <h2>后台管理系统</h2>
    <div class="tabs">
      <el-tabs stretch v-model="activeName" class="demo-tabs">
        <el-tab-pane label="账号登录" name="account">
          <template #label>
            <el-icon class="user-icon"><UserFilled /></el-icon>
            <span>账号登录</span>
          </template>
          <!-- 账号登录 -->
          <PanelAccount ref="paneAccount" />
        </el-tab-pane>
        <el-tab-pane label="手机登录" name="phone">
          <template #label>
            <el-icon class="user-icon"><Iphone /></el-icon>
            <span>手机登录</span>
          </template>
          <!-- 手机登录 -->
          <PanelPhone />
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="controls">
      <div class="pwd">
        <el-checkbox v-model="isRememberPassword" label="记住密码" size="large" />
        <el-link type="primary">忘记密码</el-link>
      </div>
      <el-button size="large" class="login-btn" type="primary" @click="handleLoginBtnClick">立即登录</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue'
import PanelAccount from './PanelAccount.vue'
import PanelPhone from './PanelPhone.vue'
import { localCache } from '@/utils/cache'

// 是否记住密码
const isRememberPassword = ref<boolean>(localCache.getCache('isRememberPwd') ?? false)
watch(isRememberPassword, (newVal) => {
  localCache.setCache('isRememberPwd', newVal)
})

const activeName = ref('account')
// 拿到account组件
const paneAccount = ref<InstanceType<typeof PanelAccount>>()
// 立即登录业务逻辑
const handleLoginBtnClick = () => {
  if (activeName.value == 'account') {
    paneAccount.value?.accountAlian(isRememberPassword.value)
    console.log('账号登录')
  } else {
    console.log('手机登录')
  }
}
</script>

<style lang="less" scoped>
.login-panel {
  width: 330px;
}
h2 {
  text-align: center;
  font-size: 25px;
  font-weight: 900;
}

.controls {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;

  .pwd {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}

.login-btn {
  text-align: center;
  width: 100%;
}

.user-icon {
  margin-right: 10px;
}
</style>
